<template>
    <div>
        <el-card>
            <el-button type="info" icon="el-icon-arrow-left" size="mini" @click="myReturn">返回</el-button>
            <el-form ref="form" :model="form">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="活动区域">
                            <span slot="label">
                                <span class="label-text">
                                    类型
                                </span>
                            </span>

                            <el-select v-model="form.type" placeholder="请选择类型" style="width:100%;">
                                <el-option v-for="item in type" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item>
                            <span slot="label">
                                <span class="label-text">
                                    备注
                                </span>
                            </span>
                            <el-input v-model="form.memo"></el-input>
                        </el-form-item>

                    </el-col>

                </el-row>
                <el-form-item class="sub-btn">
                    <el-button type="primary" @click="saveAtt">保存</el-button>
                    <el-button @click="myCancel">取消</el-button>
                </el-form-item>
            </el-form>

        </el-card>

    </div>
</template>

<script>


export default {
    name: "addCheManage",
    data() {
        return {
            form: {
                memo: "",
                type: "",
            },
            type: [],
        }
    },
    methods: {
        myReturn() {
            this.$router.push("/chenManage")
        },
        // 获取类别
        async getType() {
            let res = await this.$api.checking.getTypeList({ currentPage: 1, pageSize: 1 });
            this.type = [...res.data.data.list];
            for (let i = 0; i < this.type.length; i++) {
                if (this.type[i].value == 1) {
                    this.type[i].label = "上班"
                } else if (this.type[i].value == 2) {
                    this.type[i].label = "下班"
                } else if (this.type[i].value == 3) {
                    this.type[i].label = "外出"
                } else if (this.type[i].value == 4) {
                    this.type[i].label = "请假"
                } else if (this.type[i].value == 5) {
                    this.type[i].label = "加班"
                }
            };
            
            console.log(this.type);
        },
        //增加考勤信息
        async saveAtt() {
            //  let myData=JSON.stringify(this.form) 
            // console.log(myData.memo);
            let res = await this.$api.checking.addAttend({
                memo:this.form.memo,
                type:parseInt(this.form.type),
            });
            console.log(res);
            // console.log(this.form);
            this.$router.push("/chenManage")
        },
        myCancel() {
            this.$router.push("/chenManage")
        }

    },
    created() {
        this.getType()
    }

}
</script>

<style  scoped>
.label-text {
    font-weight: 700;
    font-size: 14px;
    color: #333;
}

.sub-btn {
    margin-top: 20px;
    text-align: left;
}

;
</style>